class Solution {
public:
    vector<string> res;
    
    void dfs(int left, int right, string current) {
        // dfs 每一次尝试，都使用新的字符串变量，所以无需要回溯
        if (left == 0 && right == 0) {
            res.push_back(current);
            return;
        }
        if (left > right) return ;
        if (left > 0) dfs(left - 1, right, current + '(');
        if (right > 0) dfs(left, right - 1, current + ')');
    }
    
    
    vector<string> generateParenthesis(int n) {
        dfs(n, n, "");
        return res;
    }
};
